package my.study.demo.outputinputstream;

import java.io.FileOutputStream;
import java.io.IOException;

//https://blog.csdn.net/weixin_33583401/article/details/114554960
//使用键盘输入一段文章，将文章保存在文件write.txt中
public class FileOutputStreamTest {
    public static void main(String args[]) throws IOException  {

        try{

            System.out.println("please Input from Keyboard");
            int count, n = 512;
            byte buffer[] = new byte[n];


            count=System.in.read(buffer);

            FileOutputStream wf= new FileOutputStream("e:/myjava/write.txt");

            wf.write(buffer,0, count);

            wf.close();//当流写操作结束时，调用close方法关闭流。

            System.out.println("Save to the write.txt");
        }catch(IOException IOe) {
                System.out.println(IOe);
            System.out.println("File Write Error!");
        }
    }
}
